﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnGroundSenser : MonoBehaviour {

	public CapsuleCollider cap;

	public float offset = 0.1f;

	private Vector3 pointDown;
	private Vector3 pointUp;
	private float radius;
	void Awake () {
		radius = cap.radius - 0.05f;
	}
	void FixedUpdate () {
		
		pointDown = transform.position + transform.up * (radius - offset);
		pointUp = transform.position + transform.up * (cap.height - offset) - transform.up * radius;

		Collider[] outputCols = Physics.OverlapCapsule(pointDown, pointUp, radius, LayerMask.GetMask("Ground"));
		if (outputCols.Length != 0)
		{
			SendMessageUpwards("IsGround");
		}
		else
		{
			SendMessageUpwards("IsNotGround");
		}
	}
}
